package com.woniu;

import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

public class BeanFactory {
    private static Map objects = new HashMap();
    private static Properties p = new Properties();

    static {
        try {
            p.load(BeanFactory.class.getClassLoader().getResourceAsStream("o.properties"));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public Object getByName(String name) {
        try {
            Enumeration<?> enumeration = p.propertyNames();
            while (enumeration.hasMoreElements()) {
                String key = enumeration.nextElement() + "";
                String className = p.getProperty(key);
                Object o = Class.forName(className).newInstance();
                objects.put(key, o);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return objects.get(name);
    }
}
